// 获取三级联动信息
$('#address').on('tap', function() {
    var picker = new mui.PopPicker({
        layer: 3
    });
    picker.setData(cityData3);
    picker.show(function(selectItems) {
        var province = selectItems[0].text
        var city = selectItems[1].text
        var area = selectItems[2].text
        var allAddress = province + city + area
        $("#address").val(allAddress)
    })
})

// 添加收货地址

$('#addBtnAddress').on('tap', function() {
    var user = $('#user').val().trim()
    var post_code = $('#post_code').val().trim()
    var address = $('#address').val().trim()
    var detail_address = $('#detail_address').val().trim()

    if (user.length <= 0) return mui.toast('请输入收货人姓名~');
    if (post_code.length && post_code.length < 6) return mui.toast('邮编不得少于六位~');
    if (address.length < 2) return mui.toast('请输入省市区~');
    if (detail_address.length && detail_address.length < 2) return mui.toast('请输入详细地址~');
    var params = {
        address: address,
        addressDetail: detail_address,
        recipients: user,
        postcode: post_code,
    }

    $.ajax({
        url: '/address/addAddress',
        type: 'post',
        data: params,
        success: function(res) {
            mui.toast('添加地址成功~');
            setTimeout(function() {
                window.location.href = "address.html"
            }, 500)
        }
    })
    return false
})